The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

Legacy:Bulldog Player

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Making the bulldog the player pawn[edit]

I'm a bit of a uscript n00b and this is aimed at n00bs. Just delete it if it doesn't really belong. And please edit it if it's really crap or just too simple :/

If you want the player to spawn as a bulldog, this is how you do it. Keep in mind that the player actually is the bulldog so they can never exit the vehicle.

OK, the first thing to do is to create a new bulldog which subclasses the old one. We have to do this because it's not as simple as setting the pawn class in the game info class.

class NewBulldog extends Bulldog
    placeable;
 
simulated event Destroyed()
{
    Driver = None;
    super.Destroyed();
}
 
function PostSpawn(Pawn p)
{
    local PlayerController pc;
 
    Driver = p;
    pc = BulldogSpawnPlayer(p.Controller);
    pc.GotoState('PlayerDriving');
    ClientKDriverEnter(pc);
}

The first thing that is done is in event destroyed. Because this new car won't be the same as other vehicles ie. there is no pawn inside doing the driving, it is driving itself; we have to tell the vehicle that there is no longer a driver before it is destroyed, or else it gets messy and eventually throws back a critical error.

Then there's the PostSpawn function. This function is called straight after the player spawns from the game info class. If nothing is done after the car spawns, it doesn't act like a car, the chassis just spins around when the mouse is moved. The parameter p is just the bulldog that has spawned. So first the driver is set to the car itself, because there is no driver.

Then the PlayerController class is set to PlayerDriving so the car acts like a car. Then the function ClientKDriverEnter is called, which does some stuff to the HUD (but it is also vital to the car driving, I don't know why :/ ).

Now, since there is no pawn inside the vehicle driving, we have to prevent the player from exiting when they are in the PlayerDriving state. So we create a new PlayerController class. This is fairly messy so please edit it if there is a better way to do it.

class BulldogSpawnPlayer extends xPlayer;
 
state PlayerDriving
{
ignores SeePlayer, HearNoise, Bump;
 
    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
 
    }
 
    exec function Fire(optional float F)
    {
        local KVehicle DrivenVehicle;
 
        DrivenVehicle = KVehicle(Pawn);
        if(DrivenVehicle != None)
        {
            DrivenVehicle.VehicleFire(false);
            DrivenVehicle.bVehicleIsFiring = true;
        }
    }
 
    exec function AltFire(optional float F)
    {
        local KVehicle DrivenVehicle;
 
        DrivenVehicle = KVehicle(Pawn);
        if(DrivenVehicle != None)
        {
            DrivenVehicle.VehicleFire(true);
            DrivenVehicle.bVehicleIsAltFiring = true;
        }
    }
 
    // Set the throttle, steering etc. for the vehicle based on the input provided
    function ProcessDrive(float InForward, float InStrafe, bool InJump)
    {
        local KVehicle DrivenVehicle;
 
        DrivenVehicle = KVehicle(Pawn);
 
        if(DrivenVehicle == None)
        {
            log("PlayerDriving.PlayerMove: No Vehicle");
            return;
        }
 
        // check for 'jump' to throw the driver out.
/*        if(InJump && Role == ROLE_Authority)
        {
            DrivenVehicle.bGetOut = true;
            return;
        }*/
 
        //log("Drive:"$InForward$" Steer:"$InStrafe);
 
        if(InForward > 1)
            DrivenVehicle.Throttle = 1;
        else if(InForward < -1)
            DrivenVehicle.Throttle = -1;
        else
            DrivenVehicle.Throttle = 0;
 
        if(InStrafe < -1)
            DrivenVehicle.Steering = 1;
        else if(InStrafe > 1)
            DrivenVehicle.Steering = -1;
        else
            DrivenVehicle.Steering = 0;
	}
 
    function PlayerMove( float DeltaTime )
    {
        local KVehicle DrivenVehicle;
 
        // Only servers can actually do the driving logic.
        if(Role < ROLE_Authority)
            ServerDrive(aForward, aStrafe, bPressedJump);
        else
            ProcessDrive(aForward, aStrafe, bPressedJump);
 
        // If the vehicle is being controlled here - set replicated variables.
        DrivenVehicle = KVehicle(Pawn);
        if(DrivenVehicle != None)
        {
            if(bFire == 0 && DrivenVehicle.bVehicleIsFiring)
            {
                DrivenVehicle.VehicleCeaseFire(false);
                DrivenVehicle.bVehicleIsFiring = false;
            }
 
            if(bAltFire == 0 && DrivenVehicle.bVehicleIsAltFiring)
            {
                DrivenVehicle.VehicleCeaseFire(true);
                DrivenVehicle.bVehicleIsAltFiring = false;
            }
        }
 
        // update 'looking' rotation - no affect on driving
        UpdateRotation(DeltaTime, 2);
    }
 
    function BeginState()
    {
        CleanOutSavedMoves();
    }
 
    function EndState()
    {
        CleanOutSavedMoves();
    }
}
 
defaultproperties
{
     PawnClass=Class'BulldogSpawn.NewBulldog'
}

I have just copied the state PlayerDriving from this class's parent and commented out the vehicle exit code.This is messy because I don't know how to do it any better.

        // check for 'jump' to throw the driver out.
/*        if(InJump && Role == ROLE_Authority)
        {
            DrivenVehicle.bGetOut = true;
            return;
        }*/

The only other thing from this class is the PawnClass is set to the new bulldog created before in defaultproperties. This is pretty important ;).

The final thing to do is in the game info class.

class BulldogSpawn extends xDeathMatch;
 
function RestartPlayer(Controller aPlayer) {
    Super.RestartPlayer(aPlayer);
 
    NewBulldog(aPlayer.Pawn).PostSpawn(aPlayer.Pawn);
}
 
defaultproperties
{
     MapPrefix="BS"
     BeaconName="BS"
     GameName="Bulldog Spawn"
     PlayerControllerClassName="BulldogSpawn.BulldogSpawnPlayer"
}

All that is done here is when the new bulldog spawns, the PostSpawn function is called that was written earlier. Then in defaultproperties the PlayerController class is set to the one which was written earlier. And voila, you spawn as the bulldog. Hopefully some people will find this useful :).


Hi, I tried all this out but i dont seem to ge it to work, can someone help me out,

I named my map bs-test and also putted in a bulldogfactory and stuff to

get bulldogs into my map. What else do i have to do to get it right ?

Greetz


to get this example to work (ut2003):

1. save the above classes as separate files with the filenames that correspond to the the class name (eg: NewBulldog class -> NewBulldog.uc)

2. save these files under the directory [ut2003 home dir]/BulldogSpawn

3. edit UT2003.ini, underneath the [Editor.EditorEngine] section where the other EditPackages=xxxxxxx enrties are, add the line EditPackages=BulldogSpawn

4. navigate to [ut2003 home dir]/System at the prompt and type 'ucc make'

5. from this system directory type 'UT2003 VehicleDemo?Game=BulldogSpawn.BulldogSpawn'

ps. bit of an unfair advantage, but try 'UT2003 VehicleDemo?Game=BulldogSpawn.BulldogSpawn?NumBots=20'

cheers

ehendrikd

Discussion[edit]

iZiMO: If you're creating a KVehicle subclass you could just overwrite the KDriverLeave function and make it simply always return false..? This prevents the player from leaving the vehicle and saves copying the whole Driving state from the controller class